﻿namespace Cos.Core.Module.Controller
{
    using System;

    using Cos.Core.Attributes;
    using Cos.Core.Model.Security;
    using Cos.Core.Service;

    using log4net;

    using Microsoft.Practices.Unity;

    public abstract class ModuleControllerBase : System.Web.Mvc.Controller, IModuleController
    {
        protected ILog Logger;

        protected ModuleControllerBase()
        {
            Logger = LogManager.GetLogger(this.GetType());
        }

        /**
         * The user session
         */
        //@Autowired(required = false)
        [Dependency]
        public ISessionService SessionService { get; set; }
        
        /**
     * @return true if the user is authenticated
     */
        protected bool Authenticated
        {
            get
            {
                if (SessionService == null)
                {
                    return false;
                }
                return SessionService.Authenticated;
            }
        }

        /**
         * @return the logged user
         */
        protected User getUser()
        {
            throw new NotImplementedException();
            //    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

            //if (auth != null && auth.getPrincipal() instanceof User) {
            //    return (User) auth.getPrincipal();
            //}

            //return null;
        }
    }
}